home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_018 / scrimper / printer.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  147 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3. #include <devices/printer.h>
  4.  
  5. /*
  6. **       S C R E E N   I M A G E   P R I N T E R (SCRIMPER)
  7. **
  8. **             Copyright 1986 By Perry S. Kivolowitz
  9. **
  10. **    The author grants permission to duplicate and reproduce
  11. **    this software  provided  that no commercial gain can be
  12. **    had as a consequence of  use  or  reproduction  of this
  13. **    software and that  this and other identifying informat-
  14. **    be left intact.
  15. **
  16. **    This software is provided as  a  service to the readers
  17. **    of Amazing Computing and does not imply  any commitment
  18. **    on behalf of the author to  provide support nor can the
  19. **    author be held liable  for  the  consequences of use or
  20. **    misuse of this software.
  21. **
  22. */
  23.  
  24. static struct IODRPReq  request;
  25. static struct MsgPort      *pport;
  26. extern struct Message   *GetMsg();
  27. extern struct MsgPort      *CreatePort();
  28. extern PLANEPTR     AllocRaster();
  29. extern struct Window    *w;
  30.  
  31. static struct BitMap   bm;
  32. static struct RastPort rp;
  33. static int    close_mask;
  34. static int    rast_count;
  35.  
  36. #define    PPORT        0x0001
  37. #define    PRINTER        0x0004
  38.  
  39. static struct IntuiText no_port = {
  40.     0,1,JAM1,10,16,NULL,(UBYTE *) "Could Not Allocate Printer Port" , NULL
  41. };
  42.  
  43. static struct IntuiText no_lp = {
  44.     0,1,JAM1,20,16,NULL,(UBYTE *) "Could Not Open Printer" , NULL
  45. };
  46.  
  47. static struct IntuiText no_mem2 = {
  48.     0,1,JAM1,10,16,NULL,(UBYTE *) "asynchronous print. Continue?",NULL
  49. };
  50.  
  51. static struct IntuiText no_mem = {
  52.     0,1,JAM1,30,5,NULL,(UBYTE *) "Not enough chip memory for",&no_mem2
  53. };
  54.  
  55. static struct IntuiText ru_sure = {
  56.     0,1,JAM1,22,5,NULL,(UBYTE *) "Print The Screen?" , NULL
  57. };
  58.  
  59. static struct IntuiText yes = {
  60.     0 , 1 , JAM1 , 6 , 4 , NULL , (UBYTE *) "Yes" , NULL
  61. };
  62.  
  63. static struct IntuiText ok = {
  64.     0 , 1 , JAM1 , 7 , 4 , NULL , (UBYTE *) "OK" , NULL
  65. };
  66.  
  67. static struct IntuiText no = {
  68.     0 , 1 , JAM1 , 7 , 4, NULL , (UBYTE *) "No" , NULL
  69. };
  70.  
  71. dump_screen(s , bx , by , width , height)
  72. struct Screen *s;
  73. {
  74.     register struct IODRPReq *req = &request;
  75.     struct RastPort *drp = &rp;
  76.     int result;
  77.     int i;
  78.  
  79.     if (s->FirstWindow == NULL) DisplayBeep(s);
  80.     else {
  81.         close_mask = 0;
  82.         ScreenToFront(s);
  83.         Delay(30L);
  84.         ScreenToFront(w->WScreen);
  85.         result = AutoRequest(w,&ru_sure,&yes,&no,0L,0L,200L,60L);
  86.         if (!result) return;
  87.         InitRastPort(&rp);
  88.         InitBitMap(&bm,(long)s->BitMap.Depth,(long)width,(long)height);
  89.         rp.BitMap = &bm;
  90.         for (i = 0 , rast_count = 0; i < s->BitMap.Depth; i++) {
  91.             bm.Planes[i] = AllocRaster((long) width,(long) height);
  92.             if (!bm.Planes[i]) {
  93.                 free_rasters(width , height);
  94.                 result = AutoRequest(w,&no_mem, &yes,&no,0L,0L,300L,60L);
  95.                 if (!result) return;
  96.                 drp = &s->RastPort;
  97.                 break;
  98.             }
  99.             rast_count++;
  100.         }
  101.         if (drp == &rp) {
  102.             Delay(60L);
  103.             ClipBlit(&s->RastPort,(long)bx,(long)by,drp,0L,0L,(long)width,(long)height,0xC0L);
  104.             bx = by = 0;
  105.         }
  106.         if ((pport = CreatePort(NULL , 0L)) == NULL) {
  107.             (void) AutoRequest(w,&no_port,&ok,NULL,0L,0L,300L,60L);
  108.             close_down_printer(width , height);
  109.             return;
  110.         }
  111.         close_mask |= PPORT;
  112.         if (OpenDevice("printer.device",0L,req,0L)) {
  113.             (void) AutoRequest(w,&no_lp,&ok,NULL,0L,0L,300L,60L);
  114.             close_down_printer(width , height);
  115.             return;
  116.         } 
  117.         close_mask |= PRINTER;
  118.         req->io_Message.mn_ReplyPort = pport;
  119.         req->io_Command = PRD_DUMPRPORT;
  120.         req->io_RastPort = drp;
  121.         req->io_ColorMap = s->ViewPort.ColorMap;
  122.         req->io_Modes    = s->ViewPort.Modes;
  123.         req->io_SrcX = bx; req->io_SrcY = by;
  124.         req->io_DestCols = req->io_SrcWidth = width;
  125.         req->io_DestRows = req->io_SrcHeight = height;
  126.         req->io_Special = 0x8C;
  127.         DoIO(req);
  128.         close_down_printer(width , height);
  129.     }
  130. }
  131.  
  132. close_down_printer(w , h)
  133. {
  134.     while (GetMsg(pport));
  135.     free_rasters(w , h);
  136.     if (close_mask & PRINTER) CloseDevice(&request);
  137.     if (close_mask & PPORT) DeletePort(pport);
  138. }
  139.  
  140. free_rasters(width , height)
  141. {
  142.     register int i;
  143.  
  144.     for (i = 0; i < rast_count; i++) FreeRaster(bm.Planes[i] , (long) width , (long) height);
  145. }
  146.  
  147.